#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPropertyAnimation>
#include<QParallelAnimationGroup>
#include<QSequentialAnimationGroup>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QPropertyAnimation *a1 = new QPropertyAnimation(ui->pushButton,"geometry");
    a1->setDuration(3000);
    a1->setStartValue(ui->pushButton->geometry());
    a1->setEndValue(QRect(50,50,100,50));

    QPropertyAnimation *a2 = new QPropertyAnimation(ui->pushButton_2,"geometry");
    a2->setDuration(3000);
    a2->setStartValue(ui->pushButton_2->geometry());
    a2->setEndValue(QRect(150,50,100,50));

    QPropertyAnimation *a3 = new QPropertyAnimation(ui->pushButton_3,"geometry");
    a3->setDuration(3000);
    a3->setStartValue(ui->pushButton_3->geometry());
    a3->setEndValue(QRect(250,50,100,50));


    QPropertyAnimation *a4 = new QPropertyAnimation(ui->pushButton_4,"geometry");
    a4->setDuration(3000);
    a4->setStartValue(ui->pushButton_4->geometry());
    a4->setEndValue(QRect(50,250,100,50));
    QPropertyAnimation *a5 = new QPropertyAnimation(ui->pushButton_5,"geometry");
    a5->setDuration(3000);
    a5->setStartValue(ui->pushButton_5->geometry());
    a5->setEndValue(QRect(150,250,100,50));
    QPropertyAnimation *a6 = new QPropertyAnimation(ui->pushButton_6,"geometry");
    a6->setDuration(3000);
    a6->setStartValue(ui->pushButton_6->geometry());
    a6->setEndValue(QRect(250,200,100,50));

    QEasingCurve curve;
    curve.setType(QEasingCurve::OutBounce);
    curve.setAmplitude(1.0);
    curve.setOvershoot(1.7);
    curve.setPeriod(0.3);

    a1->setEasingCurve(curve);
    a2->setEasingCurve(curve);
    a3->setEasingCurve(curve);
    a4->setEasingCurve(curve);
    a5->setEasingCurve(curve);
    a6->setEasingCurve(curve);

    QParallelAnimationGroup *g1 = new QParallelAnimationGroup;
    g1->addAnimation(a1);
    g1->addAnimation(a2);
    g1->addAnimation(a3);

    QParallelAnimationGroup *g2 = new QParallelAnimationGroup;
    g2->addAnimation(a4);
    g2->addAnimation(a5);
    g2->addAnimation(a6);

    QSequentialAnimationGroup *gall = new QSequentialAnimationGroup;

    gall->addAnimation(g1);
    gall->addAnimation(g2);

    gall->start();
}

MainWindow::~MainWindow()
{
    delete ui;
}
